package com.dc.juc.example._8_syncContainer;

import com.dc.juc.annoations.NotThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Vector;

/**
 * Description: 同步容器_Vector, 读、删除操作同时处理
 * @author: gdc
 * @date: 2021/8/7
 * @version 1.0
 */
@NotThreadSafe
@Slf4j
public class Vector2 {

    public static List<Integer> LIST = new Vector<>();

    public static void main(String[] args) {
        while (true) {
            for (int i = 0; i < 10; i++) {
                LIST.add(i);
            }

            new Thread(() -> {
                for (int i = 0; i < LIST.size(); i++) {
                    LIST.remove(i);
                }
            }).start();

            new Thread(() -> {
                for (int i = 0; i < LIST.size(); i++) {
                    System.out.print(LIST.get(i));
                }
            }).start();
        }
    }

}
